Skip to content

feat: rewrite the CLI in Rust (native binary, no Node) - #10

Merged
kherembourg merged 184 commits into
mainfrom
feat/rust-cli
Nov 18, 2026
Merged

kherembourg merged 184 commits into
mainfrom
feat/rust-cli

Conversation

@kherembourg

@kherembourg kherembourg commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR rewrites the purchasely CLI from TypeScript/Node to Rust. The release is one native binary for darwin-arm64, darwin-x64, linux-x64 and linux-arm64. Users do not need Node any more.

The commands, flags, output, exit codes, config files, credentials and keychain entries do not change. A contract suite proves this against recordings of the TypeScript CLI.

What changes

  • Source: src/ (TypeScript), test/, package.json, package-lock.json and scripts/build.mjs are removed. The Cargo workspace replaces them:
    • crates/purchasely: the CLI, with the same modules (commands/, core/, surfaces/, games/).
    • crates/contract: the contract harness. It replays contract/cases/*.json (recorded from the TS CLI at be1b1ae) through a fake host, and runs the real binary for contract/bin/*.json.
  • CI (.github/workflows/ci.yml): cargo fmt, cargo clippy --workspace --all-targets and cargo test --workspace. The Node jobs are removed.
  • Build (.github/workflows/build.yml): a matrix for the 4 targets. Linux uses static musl through zigbuild. macOS binaries are stripped and ad hoc signed. A smoke job runs --version on each runner. The pack job checks the 0.9.0 bridge with the frozen old installer and the real binaries, with no node on the PATH.
  • Release (.github/workflows/release.yml): a v* tag builds, creates a GitHub release with immutable assets and SHA256SUMS, deploys Pages, and commits Formula/purchasely.rb to main. A rerun is safe:
    • It verifies every asset, including the bridge on its own tag.
    • It publishes a release that stays a draft.
    • An older version does not move Pages or the formula back.
  • Packaging: scripts/pack-release.sh packs the per-target archives and the --bridge archive. scripts/update-formula.sh writes the formula, and packaging/ holds bridge.env, site.env and the legacy Node shim.
  • Install: install.sh installs the native binary with no Node. It uses the same managed install root as before.
  • Homebrew: Formula/purchasely.rb is new. The release job updates it for each stable version from 1.0.0.
  • Docs: README.md, AGENTS.md, docs/*.md and site/index.html describe the native install and Homebrew.

Migration of the existing installs

The first release is 0.9.0, a bridge in the old archive format. An old Node install takes it at its daily update check, with its old install.sh. The bridge then starts the native binary, and rewrites the launcher so the next start does not need Node. 1.0.0 is the first native-only release. During the first 2 native releases, latest.json keeps version at 0.9.0 and puts the native version in native.

Intended differences from the TS CLI

The intended_diff field of each changed case in contract/cases/ records the reason. The main ones:

  • update and the install kind detect Homebrew (/Cellar/) first.
  • TLS reads SSL_CERT_FILE, with NODE_EXTRA_CA_CERTS as an alias.
  • apply --dry-run shows the normalized URL when the plan URL has .. segments.

Tests

  • cargo test --workspace in CI: unit tests, the contract replay of all recorded cases, the binary cases, the install and release fixture tests.
  • The bridge acceptance ran on the real 0.9.0 binaries: fresh install and --upgrade-only from 0.7.2, then a start with no node on the PATH.
  • Three independent final reviews (Codex, Fable, Codex Astra) and a verification pass. All findings are fixed with a test.

Not tested before the release: the real Homebrew install, the live Pages deploy and the real user keychain.

After the merge

  1. The staff repo pins its public submodule to the merge commit.
  2. Tag v0.9.0 (bridge), then commit chore(release): 1.0.0 and tag v1.0.0.

🤖 Generated with Claude Code

kherembourg and others added 30 commits November 18, 2026 12:09
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Register the contract modules, re-export CliError in ext, add serde to
the contract crate, and use the contract crate in the inventory test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keychain, ExecOpts, ExecResult, ExecError and NetError follow the TS
types of core/types.ts. The macos-14 image is no longer available.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Add webpki-roots for the extra CA roots of core/tls, share SurfaceDef
between core/ext and core/credentials, and fix a clippy lint in a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
A PID was replaced as a substring, so it changed digits inside UUIDs and
other numbers, and every UUID became the same token. Number the UUIDs to
keep their correlation, drop the step pid before the JSON round trip, and
pin the actions of the drift workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The recorder walked the parent directory of every absolute env path,
system directories included, and followed symlinks (ELOOP on /bin/X11).
It now walks only the temporary test directories, records a symlink
without following it, and creates its output directory. Real spawns try
again on ETXTBSY, which made a keychain test flaky on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
The keychain test changed PATH for the whole process and the state tests
shared one temporary directory, so parallel tests failed at random.
SecurityKeychain now takes the program path, each state test gets its
own directory, and the lock test prints the child output on failure.
Also build a Runtime in the acme replay test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… drift

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two processes could judge the same lock stale. The first removed it and took
the lock. The second then removed the live lock of the first by path, and both
ran the critical section (lost writes). The TS CLI has the same race.

The takeover now holds an OS lock on the lock file and checks the inode before
the unlink. The file name, the content and the stale rules do not change.

A stale lock that could not be removed made the loop spin with no timeout.
It now ends with "state lock timeout", as in the TS CLI.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
TS withLock takes a timeout: ai waits 300,000 ms and a background run
passes -1 to try once. with_lock keeps the 5,000 ms default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
kherembourg and others added 7 commits November 18, 2026 12:09
…step

dash (the sh of Ubuntu runners) does not set SHELL, and the old installer reads it under set -u.
A new test runs the step as on a runner: dash as sh, a clean environment, crate version 0.9.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gh applies --jq to each page: after 30 releases the count had two lines and the job failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nce page, README and LICENSE

- the bridge ships package.json {"type":"commonjs"}: a parent "type": "module" broke the shim
- the bridge pack writes reference.html and the real man page (0.9.0 is the Pages snapshot)
- each native archive holds README.md and LICENSE (plan 4.2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…commander

commander copies the positional setting of the parent when a command is made. The dashboard module
turns it on for the root: the commands made after it (demo, Management, extension modules) and their
subcommands stop reading their options at their subcommand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h now prints the help)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kherembourg and others added 20 commits November 18, 2026 12:32
…hout Node

The bridge PR carries the bridge version (plan 4.7 step 1). The frozen
installer refused the archive while the binary printed 0.7.2. The
real-binary step now also runs the Node launcher once, checks that the
shim wrote the native launcher, and runs it with no node on PATH.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As TS main.ts (env.XDG_CONFIG_HOME || join(homedir(), ...)), an empty
XDG_CONFIG_HOME, XDG_STATE_HOME or XDG_CACHE_HOME is unset. Without
HOME, the home comes from the account database as Node homedir() does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
std::env::vars and std::env::args panic on an invalid UTF-8 byte and put
the value in the message. Read the OS strings and replace an invalid
byte with U+FFFD, as process.env and process.argv do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… sends

TS checkAllowlist reads the app in new URL(url).pathname and decodes it
as UTF-8. The Rust check split the whole URL, so a query after the app
id named a wrong app. Parse the URL as fetch does, refuse a write with
no app when a list applies, and send a plan request to the same
normalized URL that the check read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hod in the name

Three gaps of the raw api command against TS src/commands/api.ts:
- --data with inline JSON or @file read stdin and waited on an open pipe;
  readData reads stdin for - only.
- the URL parser of TS encodes a non-ASCII path character (cafe with an
  accent is caf%C3%A9); the Rust URL kept the literal character.
- execute takes the name api-<method>, so a plan records api-patch, not api.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- TS check refuses a present confirm that is not "query" or "body"
  (false, null, a number) before any request. Rust dropped a non-string
  value, so a later entry could go out.
- TS emit gets the parsed options: --output table prints a table, and
  the context is env "-" with no key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TS check emits with the options of the command (emit(d, g, ...)) and
env rt.env(g). Rust built default options, so update --out <file>
printed to stdout and wrote no file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TS grid uses String length, slice and padEnd, which count UTF-16 code
units, and shrinks the first widest column. Rust cut a String at a byte
index, which panicked inside a multi-byte character (exit 1 after a
successful request), and shrank the last widest column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TS execFile starts its timer at spawn and writes the input while it
waits. Rust wrote the whole input first, so a child that did not read
its stdin blocked the caller with no timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TS layout lets readdirSync of the skills dir throw before any copy or
prune. Rust read a missing or unreadable dir as an empty list, copied
the references, removed the registered skills and recorded the update.
Now the error stops the agent first: files and registration stay, and
the downloaded payload is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rite

TS updatePlugins throws when the release lookup, the state lock or the
state write fails. Rust returned success. The error now goes to the
caller; the detached background update still drops it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TS rmSync (force) throws on any error but a missing path, before the
registration changes. Rust ignored the error, answered removed and
dropped the registration of a plugin still on disk. Uninstall and the
prune of an update now stop on that error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The recordings keep the TS field timedOut. The fake host read timed_out,
so every replayed exec came back with timed_out false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…notes

- The native release count skips the tag of the run: a rerun of 1.0.1
  counted 1.0.1 itself and left the bridge window early.
- A rerun finds the release published: it checks the asset set and the
  checksums of the published assets and creates nothing. The formula
  commit is skipped when the formula did not change.
- Plan 4.6: the window releases and the third native release prepend
  the reinstall line for a copy that missed the bridge window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A descendant that inherited stdin, stdout or stderr kept the call
waiting after the deadline killed the direct child. The readers now
send their chunks on a channel that the caller drains until the
deadline, and the stdin writer is detached, as TS execFile destroys
the pipes on timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first failed uninstall removed the dir contents, marker included,
before it knew the dir itself could go. The retry then refused the
target as changed. rm_force now moves the dir aside in its parent,
removes it there, and moves it back if the removal fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The raw api command concatenated the checked path and the query, so a
query value kept a literal apostrophe and a path such as entry{v} was
sent with literal braces. The URL now goes through the WHATWG
serializer, and as in TS a path whose serialized pathname differs from
the checked path is refused with exit 2 before any dry run, plan or
request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
apply checked the Management prefix on the stored URL and showed that
string in the dry run and the approval, but sent the URL after the
WHATWG normalisation, which can remove the prefix with dot segments.
The URL is now normalised once in the preflight check, and the dry
run, the approval and the send all use that checked URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on the newest release

- A rerun of a window release checks the bridge listed in its SHA256SUMS
  from the immutable v0.9.0 tag, and requires a checksum line for every
  attached archive.
- A draft left by an interrupted run gets this run's assets, is verified
  and is published before the Pages and formula jobs run.
- Pages deploys the published release assets, with latest.json rehashed
  from them, instead of the rebuilt files of the run.
- A run older than the latest stable release (sort -V) skips the Pages
  and formula jobs and does not take the Latest mark.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a jobs

A rerun of failed jobs keeps the prepare outputs of its first attempt,
so a gate step in the deploy and formula jobs repeats the sort -V check
before they promote. A prerelease draft is published without the Latest
mark. Tests cover the gates, a missing checksum line, a prerelease draft
and the formula input from the release assets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kherembourg
kherembourg marked this pull request as ready for review November 18, 2026 18:15
@kherembourg
kherembourg merged commit ae77aa6 into main Nov 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants